//****************************************************
// Porman Project 
// Filename: CRenderWindow.cpp
// Date: 2011/01/12
// Author: KengYu Lin
// Modify:
//****************************************************
#include "porman_gl/include/CDeviceCreator.h"
#include "CRenderWindow.h"
#include "CRenderSystem.h"

namespace Porman
{

namespace RS
{

CRenderWindow::CRenderWindow( const std::string& sName, unsigned int uiHash ) : 
CRenderTarget(sName,uiHash),
m_pCanvas(NULL) 
{
}

CRenderWindow::~CRenderWindow( void ) 
{
}

void CRenderWindow::initial( GL::CRenderCanvas* pCanvas )
{
    m_pCanvas = pCanvas;
    CRenderTarget::initial( getWidth(), getHeight() );
}   

void CRenderWindow::getMetrics( int& iWidth, int& iHeight )
{
    RECT rect; ::GetClientRect( m_pCanvas->m_hWnd, &rect );
    m_hRTData.getData().m_iWidth = rect.right;
    m_hRTData.getData().m_iHeight = rect.bottom;

    iWidth = rect.right;
    iHeight = rect.bottom;
}

int CRenderWindow::getWidth( void )
{
    RECT rect; ::GetClientRect( m_pCanvas->m_hWnd, &rect );
    m_hRTData.getData().m_iWidth = rect.right;
    return rect.right;
}

int CRenderWindow::getHeight( void )
{   
    RECT rect; ::GetClientRect( m_pCanvas->m_hWnd, &rect );
    m_hRTData.getData().m_iHeight = rect.bottom;
    return rect.bottom;
}

void CRenderWindow::swapBuffer( void ) 
{ 
    CRenderSystem::getSingleton().getDevice()->swapBuffer( m_pCanvas, false ); 
}

}//End RS

}//End namespace Porman